local queue     = require "skynet.queue" 
local algorithm = require "algorithm"
local M={} 

function M.new(size)
    local hash = size and algorithm.hash
    local array=setmetatable({},{__index=function (t,k)
		    local lock=queue()
		    t[k]=lock
            return lock
    end})
    return function(key,f,...)
        if size then
            key=hash(key)%size+1
        end
        
        return array[key](f,...)
    end
end

return M